package dk.au.cs.bdsi.core.repositories;


/**
 * Interface for any repository capable of storing objects of type V
 * by key of type K. 
 */
public interface Repository <K,V> extends FIFO<V> {
	/**
	 * Retrieve (get) value with given identifying key
	 * @param key Identifying key
	 * @return Value or null if no such key exists
	 */
	public V get(K key);
	
	/**
	 * Store value with the supplied key overriding 
	 * any other value identified by key (if any).<br/>
	 * If any value is overridden by this call, the new value
	 * will be added to the fifo, removing the old value if it
	 * is present in the fifo as well.
	 *  
	 * @param key Identifying key
	 * @param value Value to store
	 */
	public void store(K key, V value);
	
	/**
	 * Store value with an autogenerated key, which
	 * will <b>never</b> override any existing value, i.e.
	 * the generated key will not match any existing key.<br/>
	 * The value added will also be added to the fifo.
	 * 
	 * @param value Value to store
	 * @return Identifying key for newly stored value
	 */
	public K store(V value);
	
	/**
	 * Remove any valued stored by the given identifying key.<br/>
	 * If the fifo currently contains the value associatd with this
	 * key, it will be removed from it.
	 * 
	 * @param key Identifying key
	 */
	public void remove(K key);
	
	/**
	 * Checks whether the repository currently contains any
	 * value identified by the given key.
	 * 
	 * @param key Identifying key
	 * @return true if a value exists, false otherwise
	 */
	public boolean has(K key);
}
